import axios from 'axios';
import {API_VERSION} from '../api';
var qs = require('qs');
// 根据ID，获取地址列表
export const getAddresses = id => {
  let myid = `pid=` + id;
  return axios.get(API_VERSION + 'address_dicts', {params: {filters: myid}});
};
// 根据ID，设置 默认
export const modifyIsDefault = (id, userId, addressType) => {
  return axios.get(API_VERSION + 'address_modify_is_default', {params: {id: id, userId: userId, addressType: addressType}});
};
// 根据ID，取消 默认
export const modifyIsNotDefault = (id, userId, addressType) => {
  return axios.get(API_VERSION + 'address_modify_not_is_default', {params: {id: id, userId: userId, addressType: addressType}});
};

// 批量删除地址
export const batchAddressDel = id => {
  return axios.delete(API_VERSION + 'address_batch_delete/' + id.join(','));
};

// 保存地址
export const saveAddress = (params) => {
  return axios.post(API_VERSION + 'address', params);
};

// 根据条件获取地址址列表
export const searchAddresses = params => {
  return axios.get(API_VERSION + 'address', {params: params});
};

// 获取所有地址
export const getAllAddress = params => {
  return axios.get(API_VERSION + 'address_dicts/tree/contain/type/lazy', {params: params});
};

// 获取符合条件的地址
export const getConditionAddress = params => {
  return axios.get(API_VERSION + '/address_dicts/by_conditions', {params: params});
};

// 获取所有省份
export const getAllProvinces = params => {
  return axios.get(API_VERSION + 'address_dicts', {params: params});
};

// 添加一个新地址字典
export const addNewAddress = (province, city, county, town, isSpecial) => {
  return axios.post(API_VERSION + 'address_dicts/new', qs.stringify({province: province, city: city, county: county, town: town, isSpecial: isSpecial}));
};

// 删除一个地址字典
export const deletAddressDict = id => {
  return axios.delete(API_VERSION + 'address_dicts/delete/' + id);
};

// 修改地域名称
export const handleEditAddress = (id, name, isSpecial) => {
  return axios.post(API_VERSION + 'address_dicts/edit', qs.stringify({id: id, name: name, isSpecial: isSpecial}));
};
